package com.kaifamiao.servlet;

import javax.servlet.*;
import java.io.IOException;
import java.io.PrintWriter;
import java.time.LocalDateTime;
import java.util.logging.Logger;

public class HelloServlet implements Servlet {

    private final Logger logger = Logger.getLogger( this.getClass().getName() );

    public HelloServlet(){
        super();
        logger.info( "构造方法执行" );
    }

    @Override
    public void init(ServletConfig config) throws ServletException {
        logger.info( "初始化当前`servlet`实例: " + this );
    }

    @Override
    public void service(ServletRequest req, ServletResponse resp)
            throws ServletException, IOException {
        logger.info( "为客户端提供服务" );
        PrintWriter out = resp.getWriter();
        out.println( "<h1>" + LocalDateTime.now() + "</h1>");
    }

    @Override
    public void destroy() {
        logger.info( "回收当前`servlet`实例占用的资源" );
    }

    @Override
    public ServletConfig getServletConfig() {
        return null;
    }

    @Override
    public String getServletInfo() {
        return null;
    }
}
